<?php
include_once('../../php/postgre.php');
session_start();
$act =' ';
if(isset($_POST['act']))
	$act = $_POST['act'];
	
if($act=='tmpl_laporan'){
	echo 'ok___';
	$cb = new laporan();
	$cb -> view_data();
}

class laporan{
	
	function view_data(){		
		$id_bidang = (isset($_POST['b']))?abs($_POST['b']):abs($_GET['b']);
		$tahun = (isset($_POST['t']))?abs($_POST['t']):abs($_GET['t']);
		$tahunAng = get_data("SELECT * FROM spm_thn_angg where id_thn_angg = $tahun");
		
		if(!empty($id_bidang)){
			$find_bidang = "and b.id_bidang = '$id_bidang' ";
		}
		
		if(!empty($tahun)){
			$find_tahun ="and t.thn_angg='$tahun'";
		}
		
		$no = 1;
		//$pelayanan= get_datas("SELECT distinct p.id_pelayanan,p.nama_pelayanan from spm_proyeksi pr, spm_indikator i, spm_jenis_pelayanan p,spm_bidang_urusan b,spm_skpd s,spm_thn_angg t,spm_capaian_spm c where pr.id_indikator=i.id_indikator AND i.id_pelayanan=p.id_pelayanan AND p.id_bidang=b.id_bidang AND s.id_skpd=".$_SESSION['_id']." AND b.id_bidang='$id_bidang' AND c.tahun_capaian=".$tahunAng['thn_angg']."");
		//$pelayanan= get_datas("SELECT distinct p.nama_pelayanan from spm_proyeksi pr, spm_indikator i, spm_jenis_pelayanan p,spm_bidang_urusan b,spm_skpd s,spm_thn_angg t,spm_capaian_spm c where pr.id_indikator=i.id_indikator AND i.id_pelayanan= p.id_pelayanan AND p.id_bidang=b.id_bidang AND i.id_skpd= ".$_SESSION['_id']." AND p.id_thn_angg=".$tahunAng['id_thn_angg']);
		$pelayanan= get_datas("select distinct j.id_pelayanan,j.nama_pelayanan from spm_thn_angg t,spm_skpd s,spm_proyeksi pr,spm_indikator i, spm_jenis_pelayanan j,spm_bidang_urusan b where pr.id_indikator = i.id_indikator and i.id_pelayanan=j.id_pelayanan and j.id_bidang=b.id_bidang and i.id_skpd=".$_SESSION['_id']." and j.id_thn_angg=t.id_thn_angg and t.thn_angg=".$tahunAng['thn_angg']);
		if(count($pelayanan) > 0){
			foreach ($pelayanan as $pelayanan){
				$idpelayanan = $pelayanan['id_pelayanan'];
				?>
				
				<tr>
					<td style="text-align:center;"><?php echo $no?></td>
					<td colspan="14"><?php echo $pelayanan['nama_pelayanan'] ?></td>
				</tr>
				<?php
				$nmr = 1;
				//$th=("select * from spm_thn_angg where id_thn_angg=".$pelayanan['id_thn_angg']);
				//$indikator= get_datas("SELECT distinct i.nama_indikator,pr.target_pertama,pr.target_kedua,pr.target_ketiga,pr.target_keempat,pr.target_kelima from spm_proyeksi pr, spm_indikator i, spm_jenis_pelayanan p,spm_bidang_urusan b,spm_skpd s,spm_thn_angg t,spm_capaian_spm c where pr.id_indikator=i.id_indikator AND i.id_pelayanan= ".$pelayanan['id_pelayanan']." AND p.id_bidang=b.id_bidang AND b.id_bidang=s.id_bidang AND i.id_skpd= ".$_SESSION['_id']." AND p.id_thn_angg=".$th['id_thn_angg']);
				$indikator= get_datas("SELECT distinct i.nama_indikator,pr.target_pertama,pr.target_kedua,pr.target_ketiga,pr.target_keempat,pr.target_kelima from spm_proyeksi pr, spm_indikator i, spm_jenis_pelayanan p,spm_bidang_urusan b,spm_skpd s,spm_thn_angg t,spm_capaian_spm c where pr.id_indikator=i.id_indikator AND i.id_pelayanan= ".$pelayanan['id_pelayanan']." AND p.id_bidang=b.id_bidang AND b.id_bidang=s.id_bidang AND i.id_skpd= ".$_SESSION['_id']." AND p.id_thn_angg=".$tahunAng['id_thn_angg']);
				
				if(count($indikator) > 0){
					foreach($indikator as $indikator){
					
						$standart = $indikator['nilai_spm'];
						$capaian = $indikator['nilai_capaian'];
						$selisih = $standart - $capaian;
						?>
						<tr>
							
							<td></td>
							<td colspan="2"><?php echo $indikator['nama_indikator'] ?></td>
							<td ><?php echo $indikator['target_pertama'] ?></td>
							<td ><?php echo $indikator['target_pertama'] ?></td>
							<td ><?php echo $indikator['target_pertama'] ?></td>
							<td ><?php echo $indikator['target_kedua'] ?></td>
							<td ><?php echo $indikator['target_pertama'] ?></td>
							<td ><?php echo $indikator['target_ketiga'] ?></td>
							<td ><?php echo $indikator['target_pertama'] ?></td>
							<td ><?php echo $indikator['target_keempat'] ?></td>
							<td ><?php echo $indikator['target_pertama'] ?></td>
							<td ><?php echo $indikator['target_kelima'] ?></td>
							<td ><?php echo $indikator['target_pertama'] ?></td>
							<td ><?php echo $_SESSION['_skpd'] ?></td>
						</tr>
						<?php
						$nmr++;
					}
				}
			$no++;
			}
			
		}
		
	}
}

?>